package com.mpyy.handler.systemSetting;

import com.mpyy.dao.ToolsInter;
import com.mpyy.pojo.*;
import com.mpyy.service.everyday.SalesmanServicInter;
import com.mpyy.service.systemSetting.ClientServiceInter;
import com.mpyy.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @PackageName:com.mpyy.handler.systemSetting
 * @ClassName:ClientHandler
 * @Date:2022-03-25:11:15
 * @Author: Tang Neng
 */
@Controller
public class ClientHandler {
    @Autowired
    private ClientServiceInter clientServiceInter;
    /**添加会员信息*/
    @RequestMapping(value = "/updateClientInfoAdd" , method = RequestMethod.POST) @ResponseBody
    public int updateClientInfoAdd(MenmberInfo menmberInfo){
//        System.out.println(menmberInfo);
        menmberInfo.setMenStatus("1".equals(menmberInfo.getMenStatus()) ? "1" : "0");
        menmberInfo.setMenPointUpgrade("1".equals(menmberInfo.getMenPointUpgrade()) ? "1" : "0");
        int i = clientServiceInter.updateMenmberInfoAdd(menmberInfo);
        return i;
    }

    /**获取会员等级输出到页面*/
    @RequestMapping(value = "/searchClientTypeInfo",produces = "application/json;charset=UTF-8") @ResponseBody
    public String searchClientTypeInfo(){
        List<MenmberTypeld> menmberTypelds = clientServiceInter.searchMenmberTypeInfo();
        //装换成JSON格式的字符串，返回到页面
        return Tool.hashMapInfo(menmberTypelds , menmberTypelds);
    }
    @Autowired
    private ToolsInter toolInter;

    /**获取会员id进行自增操作*/
    @RequestMapping(value = "/searchClientIdInfo", method = RequestMethod.GET) @ResponseBody
    public String searchClientIdInfo(String menId , String table){
        String id = new Tool().aotomaticId(menId , table, toolInter);
        return id;
    }

    /**搜索当前会员信息输出到页面*/
    @RequestMapping(value = "/searchClientInfo" , method = RequestMethod.GET , produces = "application/json;charset=UTF-8") @ResponseBody
    public String searchClientInfo(String menName){
        List<MenmberInfo> menmberInfos = clientServiceInter.searchMenmberInfo(menName);
        return Tool.hashMapInfo(menmberInfos , menmberInfos);
    }

    /**根据会员编号查询该会员绑定了，哪些客户，在对客户消费订单进行查询*/
    @RequestMapping(value = "/searchClientSaleOrderDescInfo" , method = RequestMethod.GET , produces = "appliction/json;charset=UTF-8") @ResponseBody
    public String searchClientSaleOrderDescInfo(String menId,Paging paging){
//        System.out.println(paging);
        List<SaleOrder> saleOrderDescsPaging = clientServiceInter.searchMenmberSaleOrderDescInfo(menId , paging);
        List<SaleOrder> saleOrderDescs = clientServiceInter.searchMenmberSaleOrderDescInfo(menId , null);

//    System.out.println(saleOrderDescs);
        return Tool.hashMapInfo(saleOrderDescs , saleOrderDescsPaging);
    }

    /**修改会员信息*/
        @RequestMapping(value = "/updateClientInfo" , method = RequestMethod.GET) @ResponseBody
    public int updateClientInfo(MenmberInfo menmberInfo){
//      System.out.println("修改会员信息"+menmberInfo);
            menmberInfo.setMenStatus("1".equals(menmberInfo.getMenStatus()) ? "1" : "0");
            menmberInfo.setMenPointUpgrade("1".equals(menmberInfo.getMenPointUpgrade()) ? "1" : "0");
        int i = clientServiceInter.updateMenmberInfo(menmberInfo);
        return i;
    }

    /**删除会员信息**/
    @RequestMapping(value = "/updataClientInfoDelete") @ResponseBody
    public int updataClientInfoDelete(String menId){
        int i = clientServiceInter.updateMenmberInfoDelete(menId);
//        System.out.println("会员Id"+menId);
        return i;
    }

    @Autowired
    private SalesmanServicInter salesmanServicInter;

    /**根据销售编号查询销售明细Id**/
    @RequestMapping(value = "/searchClientSaleOrderDescInfoHandler") @ResponseBody
    public String searchClientSaleOrderDescInfoHandler(String string){
        List<SaleReturnDesc> saleReturnDescs = salesmanServicInter.searchSaleReturnDesc(string);
        return Tool.hashMapInfo(saleReturnDescs , saleReturnDescs);
    }
}
